package nyist.media.entity.admin;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import nyist.media.entity.BaseEntity;

import javax.persistence.*;
import javax.validation.constraints.Min;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;

/**
 * 管理员
 *
 * @author dcf
 * @date 2018/12/24
 */
@Getter
@Setter
@Table(name = "m_p_admin")
@Entity
public class Admin extends BaseEntity {
    private static final long serialVersionUID = -2641417455484797086L;

    /**
     * 用户名	varchar(30)	非空，唯一
     */
    @Column(nullable = false, length = 30, updatable = false, columnDefinition = "varchar(30) COMMENT '用户名'")
    private String username;

    /**
     * 姓名昵称 varchar(30) 非空
     */
    @Column(nullable = false, length = 30, columnDefinition = "varchar(30) COMMENT '姓名昵称'")
    private String name;

    /**
     * 密码	varchar(64)	非空
     */
    @Column(nullable = false, length = 64)
    private String password;

    /**
     * 登录失败次数	int	非空
     */
    @Min(0)
    @Column(nullable = false)
    private int failCount;

    /**
     * 锁定到期时间	datetime
     */
    private Timestamp lockIn;

    /**
     * 是否启用	bit(1)	非空
     */
    @Column(nullable = false, columnDefinition = "bit(1) COMMENT '是否启用管理员'")
    private boolean enabled;

    /**
     * 已有角色
     */
    @ManyToMany(targetEntity = Role.class)
    @JoinTable(name = "m_admin_roles")
    @JsonIgnore
    private Set<Role> roles = new HashSet<>();

    /**
     * 邮箱
     */
    @Column(columnDefinition = "varchar(33) COMMENT '邮箱'")
    private String email;


    /**
     * 手机号
     */
    @Column(columnDefinition = "varchar(16) COMMENT '手机号'")
    private String phone;
}

